﻿@model IEnumerable<AceMobile.Models.Order>
@{
    ViewBag.Title = "Giỏ hàng";
}
<link href="@Url.Content("~/Content/TableStyle.css")" rel="stylesheet"  type="text/css" />     
<style>
    tr:hover, tr:hover td a, tr td:hover
    {
        color: #666666;
        background-color: white;
    }
    #sumprice td:hover
    {
        background-color: #ffd800;
    }
    #content2 a:hover
    {
        color: #666666;
    }
</style>

<script>
    var tablet = "tablet";
    function amountChange(ID,type, object) {
        $.ajax({
            type: "POST",
            url: "@Url.Action("ChangeAmount")",
            data: { id:ID, type:type, amount: object.value}
        })
        .done(function (result) {
            $("#priceall").text(result.priceall + " đ");
            $("#cart").text(result.Amount);
        });
    }
    function deleteOrder(ID,type, object) {
        $.ajax({
            type: "POST",
            url: "@Url.Action("Delete")",
            data: { id: ID, type:type}
        })
        .done(function (result) {
            object.parentElement.parentElement.remove();
            $("#priceall").text(result.priceall + " đ");
            $("#cart").text(result.Amount);
        });
    }
</script>
 	    
<center>
    <h2>Các sản phẩm bạn đã cho vào giỏ hàng</h2>       
</center>
<table style="width: 800px; margin: auto">
    <tr>
        <th>
            @Html.LabelFor(a => Model.First().Name)
        </th>
        <th>
            @Html.LabelFor(a => Model.First().Type)
        </th>
        <th>
            Ảnh
        </th>
        <th>
            @Html.LabelFor(a => Model.First().Price)
        </th>
        <th>
            @Html.LabelFor(a => Model.First().Amount)
        </th>        
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>        
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>            
            @System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(item.Type.ToLower())
        </td>
        <td>
            <img src="
            @try
            {
                @Url.Content(@AceMobile.Models.Cart.GetImageFromID(item.ID))                 
            }
            catch (Exception)
            {
                @:/Content/Images/iphone.jpg           
            }
            " alt="@item.Name" />
        </td>
        <td>
            @try
            {
                @item.Price.ToString("#,##0") @:đ
            }
            catch (Exception)
            {
                                
            }
            
        </td>
        <td>
            @Html.TextBoxFor(modelItem => item.Amount, new {style="width:20px", @class="Amount", onchange="amountChange("+item.ID+",\'"+ item.Type +"\',this)"})
        </td>        
        <td>                        
            <a href="#" onclick="deleteOrder(@item.ID,'@item.Type', this)">Delete</a>
        </td>
    </tr>
}
    <tr id="sumprice" style="background-color: #ffd800">
        <td></td>
        <td></td>
        <td style="color: red; font-weight: bold">   
            Tổng tiền:         
        </td>
        <td id="priceall">
            @ViewBag.priceAll.ToString("#,##0") vnđ 
        </td>
        <td>            
        </td>        
        <td>                        
        </td>
    </tr>    
</table>  
<div style="clear:both; height: 20px;"></div>    
<div style="width: 800px; margin: auto"> 
    <b>
        @Html.ActionLink("Đặt hàng", "Order", null, new { style="color:#ff6a00; float: right; background-color: #5F5D5D; padding: 5px"})
    </b>
</div>